﻿using System;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Helper;
using Besture.Model;
using System.Data;
using Besture.UI.ClassHelper;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.Data;

namespace Besture.UI
{
    public partial class AppraisalSet : BasePage
    {
        #region 页面加载事件

        /// <summary>
        /// 页面加载
        /// </summary>
        protected override void InitialLoad()
        {
            //页面加载
            InitPage();
            //编辑编号
            InitData(ID);
            AspxGridViewHelper.InitAspxGridView(grid);
        }

        /// <summary>
        /// 回发
        /// </summary>
        protected override void PostBackLoad()
        {
            InitPage();
        }

        /// <summary>
        /// 页面加载
        /// </summary>
        public void InitPage()
        {
            var hotDt = new AppraisalDac().GetAppraisalByHotID(Convert.ToInt32(StringHelper.Query("hotId")));
            grid.DataSource = hotDt;
            grid.DataBind(); 
        }

        /// <summary>
        /// AspxGridView回发事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridCustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            if (e.Parameters == "Refresh")
                grid.DataBind();
        }

        /// <summary>
        /// 数据加载
        /// </summary>
        /// <param name="id">编号</param>
        protected void InitData(int id)
        {
            if (id == 0) return;

            var dac = new AppraisalDac();
            var model = dac.GetModel(id);
			if(model==null) return;

            if (new HotelsDac().GetModel(model.HotelsID)!=null)
                lblHotName.Text = new HotelsDac().GetModel(model.HotelsID).HotelsName;
            if (new UserBaseDac().GetModel(model.UserID) != null)
                lblUserName.Text = new UserBaseDac().GetModel(model.UserID).LoginName;
			
            lblContent.Text = model.Content.ToString();
			lblAppraisalTime.Text =  Convert.ToDateTime(model.AppraisalTime).ToString("yyyy-MM-dd");
			lblLocation.Text = model.Location.ToString();
			lblFacilities.Text = model.Facilities.ToString();
			lblService.Text = model.Service.ToString();
			lblHealth.Text = model.Health.ToString();
			  
        }
        #endregion

        #region 删除数据

        /// <summary>
        /// 删除单条数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridRowDeleting(object sender, ASPxDataDeletingEventArgs e)
        {
            e.Cancel = true;
            var id = Convert.ToInt32(e.Keys[0]);
            var dac = new ReviewsReplyDac();
            dac.Delete(id);
            InitPage();
        }

        /// <summary>
        /// 删除选中数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbDel_Click(object sender, EventArgs e)
        {
            var ids = AspxGridViewHelper.GetCheckID(grid);
            if (string.IsNullOrEmpty(ids))
            {
                return;
            }
            var dac = new ReviewsReplyDac();
            dac.DeleteList(ids);
            FunHelper.Alert("删除成功！", Request.Url.ToString());
        }

        #endregion 
    }
}